package cn.tfyhyc.springcloud.controller;

import cn.tfyhyc.springcloud.service.PaymentService;
import cn.tfyhyc.springcloud.entities.CommonResult;
import cn.tfyhyc.springcloud.entities.Payment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 头发又黑又长
 * @Date 2022/10/9 20:05
 * @email zwb15083976291@163.com
 */
@RestController
@RequestMapping("/consumer")
public class OrderFeignController {
    @Resource
    private PaymentService paymentService;

    @GetMapping("payment/{id}")
    CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        // 调用 paymentService 服务
        return paymentService.getPaymentById(id);
    }

    @GetMapping("/payment/feign/timeout")
    public String paymentFeignTimeout() {
        // openfeign-ribbon 客户端一般默认等待1秒钟
        // 如果超时将引发 java.net.SocketTimeoutException: Read timed out
        return paymentService.paymentFeignTimeout();
    }

}
